import { reactive,watch } from 'vue'

export const RoomState = reactive({
    // 初始化值从内存中取，防止页面刷新后的丢失
    currentRoom: JSON.parse(sessionStorage.getItem('currentRoom')) || {},

    setCurrentRoom(room){
        this.currentRoom = room
        sessionStorage.setItem('currentRoom',JSON.stringify(room))
    }


})


watch(() => RoomState.currentRoom, newVal => {
    sessionStorage.setItem('currentRoom', JSON.stringify(newVal))
}, {deep : true}) // deep: true 用来监听嵌套对象的变化